package biz

import (
	"go-project/common"
	"go-project/common/utils"
	"go-project/internal/dao"
	"go-project/internal/model"
	"log/slog"
)

type userBiz struct{}

var UserBiz userBiz

// Deprecated:
func (biz *userBiz) Login(dto *model.UserDto) (string, error) {
	slog.Info("login message:", "dto", dto)
	user, err := dao.UserDao.GetOne(common.DB, &model.User{Username: dto.Username})
	if err != nil {
		return "", err
	}
	//if user.Password != utils.MD5Password(loginVo.Password) {
	//	return "", errors.New("password error")
	//}

	token, err := utils.GenerateToken(user.ID, user.Username)
	if err != nil {
		return "", err
	}
	//userJson, err := json.Marshal(user)
	//if err != nil {
	//	return "", err
	//}
	//_, err = global.REDIS.Set(context.Background(), "login:token:"+token, userJson, time.Second*time.Duration(global.CONFIG.JWT.TTL)).Result()
	//if err != nil {
	//	return "", err
	//}
	return token, nil
}
